package com.chinatsp.onlineapp.ui.weather;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;

import com.chinatsp.onlineapp.R;
import com.chinatsp.onlineapp.base.BaseActivity;
import com.chinatsp.onlineapp.bean.WeatherService;
import com.chinatsp.onlineapp.presenter.WeatherServiceDao;

public class WeatherSinglePageActivity extends BaseActivity {
	
	private Context mContext;
	private ViewPager vp_weather;
	private LinearLayout ll_point;
	private List<ImageView> list = new ArrayList<ImageView>();
    private ImageView iv1;
    public int CityNum = 3;
	private LinearLayout.LayoutParams layoutParams;
	private int Rcode = 1;

	@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setRequestedOrientation(ActivityInfo
                .SCREEN_ORIENTATION_LANDSCAPE);
        setContentView(R.layout.activity_single_page);
        
        
        init();
        
//        iv1 = (ImageView) findViewById(R.id.iv1);
//        AnimationDrawable anim = (AnimationDrawable) iv1.getBackground();
//        anim.start();
        
        
    }

	private void init() {
		getData();
		initView();
		
	}
	private void getData() {
		mContext = this;
		WeatherService weatherService = new WeatherService();
		WeatherServiceDao weatherServiceDao = new WeatherServiceDao(this,  this);
		weatherServiceDao.getWeatherService("北京",Rcode);		
	}
	private void initView() {
		ImageView iv_back = (ImageView) findViewById(R.id.iv_back);
		iv_back.setOnClickListener(new OnClickListener() {			
			@Override
			public void onClick(View arg0) {
				finish();				
			}
		});
		vp_weather = (ViewPager) findViewById(R.id.vp_weather);
		ll_point = (LinearLayout) findViewById(R.id.ll_point);
		WeatherAdapter adapter = new WeatherAdapter(getSupportFragmentManager(),CityNum);
		vp_weather.setAdapter(adapter);
		for (int i = 0; i < CityNum; i++) {
			ImageView iv = new ImageView(mContext);
			LinearLayout.LayoutParams params = new LayoutParams(15,15);
			params.setMargins(24,0,24,0);
			iv.setLayoutParams(params);
			iv.setImageResource(R.drawable.point_selected);
			list.add(iv);
			ll_point.addView(iv);
		}
		setPointImageResource(0);
		
		vp_weather.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
            }
            @Override
            public void onPageSelected(int position) {
            	setPointImageResource(position);
            }
			@Override
            public void onPageScrollStateChanged(int state) {
            }
        });
		
		

		
		
	}

	protected void setPointImageResource(int position) {
		for (int i = 0; i < list.size(); i++) {
			list.get(i).setImageResource(R.drawable.point_normal);
		}
		list.get(position).setImageResource(R.drawable.point_selected);
	
		
	}
	
	





    
}
